import java.util.Scanner;
import java.util.ArrayList;
public class Main { public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        ShoppingCart cart = new ShoppingCart();

        ArrayList<Product> warehouseProducts = new ArrayList<>();
        warehouseProducts.add(new Product("雪碧","饮品",5,10));
        warehouseProducts.add(new Product("可乐","饮品",6,10));
        warehouseProducts.add(new Product("果汁","饮品",3,10));
        warehouseProducts.add(new Product("苹果","水果",2,10));
        warehouseProducts.add(new Product("香蕉","水果",1.8,10));

        while (true) {
            System.out.println("\n请选择操作：\n1. 查看仓库商品\n2. 添加商品到购物车\n3. 查看购物车\n4. 删除购物车商品\n5. 结算\n6. 退出");
            int choice = scanner.nextInt();
            scanner.nextLine();

            switch (choice) {
                case 1:
                    System.out.println("仓库：\n");
                    System.out.println("商品名称\t"+"类型\t"+"价格\t"+"数量\t");
                    for (Product product : warehouseProducts) {
                        System.out.println( product.getName()+"\t\t"+product.getType()+"\t"+product.getPrice()+"\t"+product.getQuantity());
                    }
                    break;
                case 2:
                    System.out.print("请输入要添加的商品名称：");
                    String productName = scanner.nextLine();
                    Product newProduct = null;
                    for (Product product : warehouseProducts) {
                        if (product.getName().equals(productName)) {
                            newProduct = product;
                            break;
                        }
                    }
                    if (newProduct != null) {
                        System.out.print("请输入要添加的数量：");
                        int quantity = scanner.nextInt();
                        scanner.nextLine();
                        cart.addProduct(newProduct, quantity);
                    } else {
                        System.out.println("没有找到该商品。");
                    }
                    break;
                case 3:
                    cart.viewCart();
                    break;
                case 4:
                    System.out.print("请输入要删除的商品名称：");
                    String removeProductName = scanner.nextLine();
                    cart.removeProduct(removeProductName);
                    break;
                case 5:
                    double total = cart.calculateTotal();
                    System.out.printf("总价: %.2f\n", total);
                    break;
                case 6:
                    return;
                default:
                    return;
            }
        }

    }
}
